﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using Talk.Common;
using OUtl;

namespace TalkServer
{
    partial class GroupData
    {
        const string path = "Group";
        const string sname = ".group";
        private string CurrentPath
        {
            get { return Environment.CurrentDirectory + "\\" + path; }
        }

        protected XMLDATAIO IOData = null;
        protected void initIOData()
        {
            if (IOData == null)
            {
                IOData = new XMLDATAIO(_className, CurrentPath, "123", typeof(SGROUP));
            }
        }

        public bool Load(int id,out GROUP item ,out List<string> item2)
        {
            if (!Directory.Exists(CurrentPath))
                Directory.CreateDirectory(CurrentPath);
            item = new GROUP();
            item.ID = id;
            item2 = null;

            if (File.Exists(CurrentPath + "\\" + id + sname))
            {
                IOData.FileName = id + sname;
                object obj = IOData.Load();
                if (obj != null && obj is SGROUP)
                {
                    SGROUP item3 = obj as SGROUP;
                    if (item3.Members != null)
                        item2 = item3.Members;
                    item.Main = item3.Main;
                    item.Sub = item3.Sub;
                    if (item.Sub == null)
                        item.Sub = new List<string>();
                    item.Type = item3.Type;
                    item.Name = item3.Name;
                }
                return true;
            }

            return false;
        }

        public bool Load(int id, out GROUP item)
        #region >><<
        {
            if (!Directory.Exists(CurrentPath))
                Directory.CreateDirectory(CurrentPath);
            item = new GROUP();
            item.ID = id;

            if (File.Exists(CurrentPath + "\\" + id + sname))
            {
                IOData.FileName = id + sname;
                object obj = IOData.Load();
                if (obj != null && obj is SGROUP)
                {
                    SGROUP item3 = obj as SGROUP;
                    item.Tag = item3.Members;
                    item.Main = item3.Main;
                    item.Sub = item3.Sub;
                    if (item.Sub == null)
                        item.Sub = new List<string>();
                    item.Type = item3.Type;
                    item.Name = item3.Name;

                    return true;
                }
            }

            return false;
        }
        #endregion
    }
}
